package net.lookyou.boot.demo.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.*;
import net.lookyou.boot.demo.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@ApiSort(2)
@Api(tags = "其他模块",value="controller类")
public class TestController {

    /**
     *无参get请求
     */
    @ApiOperation("无参get用法")// 为每个handler添加方法功能描述
    @GetMapping(value = "/queryNonparametricGetRequestTest")
    public Map<String, Object> queryNonparametricGetRequestTest(){
        Map<String, Object> returnMap = new HashMap<String, Object>();
        //此处省略业务sql查询。。。使用假数据模拟
        List<Map<String, Object>> data=new ArrayList<Map<String, Object>>();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("name","张三");
        map.put("city","上海");
        data.add(map);
        Map<String, Object> map1=new HashMap<String, Object>();
        map1.put("name","李四");
        map1.put("city","北京");
        data.add(map1);
        returnMap.put("code","200");
        returnMap.put("message","查询成功!");
        returnMap.put("result",data);
        return returnMap;
    }

    /**
     *有参get请求
     */
    @GetMapping(value = "/queryParameterGetRequestTest")
    @ApiOperation("有参get用法")// 为每个handler添加方法功能描述
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = User.class) })
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "username", value = "用户名称", dataType = "string", paramType = "query", required = true, defaultValue = "null"),
                    @ApiImplicitParam(name = "password", value = "用户密码", dataType = "string", paramType = "query", required = true, defaultValue = "null")
            }
    )
    public Map<String, Object> queryParameterGetRequestTest(@RequestParam(value = "username", required = false) String username,
                                                            @RequestParam(value = "password", required = false) String password){
        Map<String, Object> returnMap = new HashMap<String, Object>();
        //此处省略业务sql查询。。。使用假数据模拟
        List<Map<String, Object>> data=new ArrayList<Map<String, Object>>();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("username",username);
        map.put("password",password);
        data.add(map);
        Map<String, Object> map1=new HashMap<String, Object>();
        map1.put("username","李四");
        map1.put("password","test1234");
        data.add(map1);
        returnMap.put("code","200");
        returnMap.put("message","查询成功!");
        returnMap.put("result",data);
        return returnMap;
    }

    /**
     *有参get请求,以对象json形式
     */
    @GetMapping(value = "/queryObjectGetRequestTest")
    public Map<String, Object> queryObjectGetRequestTest(@RequestBody User user){
        Map<String, Object> returnMap = new HashMap<String, Object>();
        //此处省略业务sql查询。。。使用假数据模拟
        List<Map<String, Object>> data=new ArrayList<Map<String, Object>>();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("username",user.getName());
        map.put("password",user.getRoleId());
        data.add(map);
        Map<String, Object> map1=new HashMap<String, Object>();
        map1.put("username","李四");
        map1.put("password","test1234");
        data.add(map1);
        returnMap.put("code","200");
        returnMap.put("message","查询成功!");
        returnMap.put("result",data);
        return returnMap;
    }

    /**
     *有参get请求,以参数占位符形式
     */
    @GetMapping(value = "/queryPlaceholderGetRequestTest/{id}")
    public Map<String, Object> queryPlaceholderGetRequestTest(@PathVariable Long id){
        Map<String, Object> returnMap = new HashMap<String, Object>();
        //此处省略业务sql查询。。。使用假数据模拟
        List<Map<String, Object>> data=new ArrayList<Map<String, Object>>();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("id",id);
        data.add(map);
        returnMap.put("code","200");
        returnMap.put("message","查询成功!");
        returnMap.put("result",data);
        return returnMap;
    }

    /**
     *无参post请求
     */
    @PostMapping(value = "/queryNonparametricPostRequestTest")
    public Map<String, Object> queryNonparametricPostRequestTest(){
        Map<String, Object> returnMap = new HashMap<String, Object>();
        //此处省略业务sql查询。。。使用假数据模拟
        List<Map<String, Object>> data=new ArrayList<Map<String, Object>>();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("name","张三");
        map.put("city","广州");
        data.add(map);
        Map<String, Object> map1=new HashMap<String, Object>();
        map1.put("name","李四");
        map1.put("city","深圳");
        data.add(map1);
        returnMap.put("code","200");
        returnMap.put("message","查询成功!");
        returnMap.put("result",data);
        return returnMap;
    }

    /**
     *有参post请求,以参数形式
     */
    @PostMapping(value = "/queryParameterPostRequestTest")
    public Map<String, Object> queryParameterPostRequestTest(@RequestParam(value = "username", required = false) String username,
                                                            @RequestParam(value = "password", required = false) String password){
        Map<String, Object> returnMap = new HashMap<String, Object>();
        //此处省略业务sql查询。。。使用假数据模拟
        List<Map<String, Object>> data=new ArrayList<Map<String, Object>>();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("username",username);
        map.put("password",password);
        data.add(map);
        Map<String, Object> map1=new HashMap<String, Object>();
        map1.put("username","李四");
        map1.put("password","test1234");
        data.add(map1);
        returnMap.put("code","200");
        returnMap.put("message","查询成功!");
        returnMap.put("result",data);
        return returnMap;
    }

    /**
     *有参post请求,以对象json形式
     */
    @PostMapping(value = "/queryObjectPostRequestTest")
    public Map<String, Object> queryObjectPostRequestTest(@RequestBody User user){
        Map<String, Object> returnMap = new HashMap<String, Object>();
        //此处省略业务sql查询。。。使用假数据模拟
        List<Map<String, Object>> data=new ArrayList<Map<String, Object>>();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("username",user.getName());
        map.put("password",user.getRoleId());
        data.add(map);
        Map<String, Object> map1=new HashMap<String, Object>();
        map1.put("username","李四");
        map1.put("password","test1234");
        data.add(map1);
        returnMap.put("code","200");
        returnMap.put("message","查询成功!");
        returnMap.put("result",data);
        return returnMap;
    }

    /**
     *有参post请求,以参数占位符形式
     */
    @PostMapping(value = "/queryPlaceholderPostRequestTest/{id}")
    public Map<String, Object> queryPlaceholderPostRequestTest(@PathVariable Long id){
        Map<String, Object> returnMap = new HashMap<String, Object>();
        //此处省略业务sql查询。。。使用假数据模拟
        List<Map<String, Object>> data=new ArrayList<Map<String, Object>>();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("id",id);
        data.add(map);
        returnMap.put("code","200");
        returnMap.put("message","查询成功!");
        returnMap.put("result",data);
        return returnMap;
    }

}

